package com.ccepc.algmanage.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ccepc.common.core.util.R;
import com.ccepc.common.log.annotation.SysLog;
import com.ccepc.algmanage.service.AlgorithmInfoService;
import com.ccepc.demo.api.dto.AlgorithmInfoDto;
import com.ccepc.demo.api.dto.AlgorithmInfoListDto;
import com.ccepc.demo.api.entity.AlgorithmInfo;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


/**
 *
 *
 * @author pigx code generator
 * @date 2023-11-06 13:52:35
 */
@RestController
@RequestMapping("/algorithminfo" )
@Api(value = "algorithminfo", tags = "算法信息")
public class AlgorithmInfoController {

    @Resource
    private AlgorithmInfoService algorithmInfoService;

    @ApiOperation(value = "分页查询")
    @GetMapping("/page" )
    @PreAuthorize("@pms.hasPermission('algmanage_algorithminfo_view')" )
    public R getAlgorithmInfoPage(Page page, AlgorithmInfo algorithmInfo) {
        return R.ok(algorithmInfoService.getAlgPage(page, algorithmInfo));
    }

    @ApiOperation(value = "通过id查询")
    @GetMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('algmanage_algorithminfo_view')" )
    public R getById(@PathVariable("id" ) Integer id) {
        return R.ok(algorithmInfoService.getById(id));
    }

    @ApiOperation(value = "新增或修改同时订阅事件")
    @SysLog("新增或修改同时订阅事件" )
    @PostMapping
    @PreAuthorize("@pms.hasPermission('algmanage_algorithminfo_add')" )
    public R save(@RequestBody AlgorithmInfoDto algorithmInfoDto) {
        return R.ok(algorithmInfoService.saveAndSubs(algorithmInfoDto));
    }

    @ApiOperation(value = "修改")
    @SysLog("修改" )
    @PutMapping
    @PreAuthorize("@pms.hasPermission('algmanage_algorithminfo_edit')" )
    public R updateById(@RequestBody AlgorithmInfo algorithmInfo) {
        return R.ok(algorithmInfoService.updateById(algorithmInfo));
    }

    @ApiOperation(value = "通过ids删除")
    @SysLog("通过ids删除" )
    @DeleteMapping
    @PreAuthorize("@pms.hasPermission('algmanage_algorithminfo_del')" )
    public R removeById(@RequestBody AlgorithmInfoListDto algorithmInfoListDto) {
        return R.ok(algorithmInfoService.removeBatch(algorithmInfoListDto));
    }

}
